var Zombie = cc.Sprite.extend({
    appearPosition:cc.p(MW.ZOMBIE.X, MW.ZOMBIE.Y),
    _zombieSpeed:0,
    biteFrames:[],
    biteAnimate:null,
    biteAnimation:null,
    walkFrames:[],
    walkAnimate:null,
    walkAnimation:null,
    moveAction:null,
    ctor:function (speed) {
        this._super('#Xueshi-Attack_01.png');
        this.x = this.appearPosition.x;
	    this.y = this.appearPosition.y;
	    this._zombieSpeed = speed;

         var str = "";
         for (var i = 5; i < 7; i++) {
             str = "Xueshi-Attack_" + (i < 10 ? ("0" + i) : i) + ".png";
             var frame = cc.spriteFrameCache.getSpriteFrame(str);
             this.walkFrames.push(frame);
         }

         this.walkAnimation = new cc.Animation(this.walkFrames, 1);
         this.walkAnimate = cc.animate(this.walkAnimation);
         this.runAction(this.walkAnimate.repeatForever());

         var offset = cc.p(MW.ACTOR.X, MW.ACTOR.Y);
         this.moveAction = cc.moveTo(this._zombieSpeed, offset);
         this.runAction(this.moveAction);


         for (var i = 1; i < 7; i++) {
             str = "Xueshi-Attack_" + (i < 10 ? ("0" + i) : i) + ".png";
             var frame = cc.spriteFrameCache.getSpriteFrame(str);
             this.biteFrames.push(frame);
         }
         this.biteAnimation = new cc.Animation(this.biteFrames, 1);
         this.biteAnimate = cc.animate(this.biteAnimation);

         this.scheduleUpdate();
    },
    update:function (dt) {
    },
    destroy:function (batchNode) {
        this.visible = false;
        this.stopAllActions();
        //batchNode.removeChild(this);
    },
    collideRect:function (x, y) {
        var w = this.width, h = this.height;
        return cc.rect(x - w / 2, y - h / 4, w, h / 2+20);
    },
    killed:function(batchNode){
        cc.audioEngine.playEffect(cc.sys.os == cc.sys.OS_WP8 || cc.sys.os == cc.sys.OS_WINRT ? res.ZombieDie_wav : res.ZombieDie_mp3, false);

        this.stopAllActions();
        var offset = cc.p(this.x, MW.ZOMBIE.Y + 200);
        var moveAction = cc.moveTo(1, offset);
        var fadeAction = cc.fadeTo(1, 0);

        this.runAction(fadeAction);
        this.runAction(cc.sequence(
            moveAction
        //    cc.callFunc(this.destroy, batchNode)
        ));
    },
    bite:function(){
        this.runAction(this.biteAnimate.repeatForever());
    }
});
